package cn.hbtt.Servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.hbtt.User.Duanxin;
import cn.hbtt.User.Zhuce;
import cn.hbtt.test.Xinxi;

/**
 * Servlet implementation class WritebackServlet
 */
@WebServlet("/Writeback")
public class WritebackServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		HttpSession session = request.getSession(); 
		Zhuce z = (Zhuce)session.getAttribute("g");
		String sendto = z.getLoginName();
		String title = request.getParameter("title");
		String msgcontent = request.getParameter("msgcontent");
		String username = request.getParameter("sendto");
		
		int math = (int) (Math.random() * 9000 + 1000);
		Date date = new Date();
		SimpleDateFormat tim = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String time = tim.format(date);
		
		Duanxin d=new Duanxin();
		d.setLoginName(username);
		d.setMsgcontrnt(msgcontent);
		d.setTitle(title);
		d.setSendto(sendto);
		d.setMsgtime(time);
		
		Xinxi u=new Xinxi();
		u.add(d);
		
		
		response.getWriter().append("Index.jsp").append(request.getContextPath());
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
